package com.sgg.algorithm.sort.util;

import com.sgg.algorithm.sort.*;

import java.util.function.Consumer;

public class CommonUtil {
    public static void test(Consumer<int[]> consumer) {
        long l = System.currentTimeMillis();
        int[] arr = genArray();
        consumer.accept(arr);
        System.out.println("耗时" + (System.currentTimeMillis() - l) + "豪秒");
        System.out.println(isSort(arr));
        System.out.println("======================================================");
    }

    public static int[] genArray() {
        int size = 8000000;
        int[] arr = new int[size];
        for (int i = 0; i < size; i++) {
            arr[i] = (int) (Math.random() * size*100);
        }
        return arr;
    }

    public static boolean isSort(int[] arr) {
        for (int i = 0; i < arr.length - 1; i++) {
            if (arr[i] > arr[i + 1]) {
                return false;
            }
        }
        return true;
    }

    public static void main(String[] args) {
//        CommonUtil.test(BubbleSort::sortImprove);
//        CommonUtil.test(SelectSort::sort);
//        CommonUtil.test(InsertSort::sort);
//        CommonUtil.test(InsertSort::insertSort);
//        CommonUtil.test(ShellSort::sortMove);
//        CommonUtil.test(ShellSort::sortExchange);
        CommonUtil.test(QuickSort::sort);
        CommonUtil.test(MergeSort::sort);
        CommonUtil.test(RadixSort::sort);
        CommonUtil.test(HeapSort::sort);

    }
}
